/*
 * Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
 *
 * Licensed under the Mulan PSL v2.
 * You can use this file according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of the License at
 *
 *     http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
 * FOR MORE DETAILS.
 */

#pragma once
#include <functional>
#include <iostream>
#include <memory>

#include "DBManager/Common/DBManagerExport.h"
#include "DBManager/IRepository/Input/Constraint/IRElementSummaryRepository.h"
#include "DBManager/IService/Input/Constraint/IRElementSummaryService.h"
#include "DBManager/Service/Input/InputServiceBase.h"

/**
 * @brief    对通用Element的一些统计的接口
 *
 * @author   wuxingchuang
 * @date     2024.12.24
 */
SG_DBMANAGER_NAMESPACE_OPEN

class DBManager_DECLSPEC RElementSummaryService : public IRElementSummaryService, public InputServiceBase<IRElementSummaryRepository>
{
  public:
    explicit RElementSummaryService (DBServiceFactory* const dbServiceFactory, IRElementSummaryRepository& repos);

    ~RElementSummaryService () override;

    /** @brief 模型中包含的单元类型 （不包含R单元）
     */
    std::vector<SG::DataStructure::FEM::RElementType> GetAllRElementTypes () const override;

    /**
     * @brief   : 获取指定Eid的类型
     */
    SG::DataStructure::FEM::RElementType GetRElementType (SG::DataStructure::Common::Id eid) const override;

    /** @brief 类型为`type`的单元的数量 */
    std::size_t GetRElementSize (SG::DataStructure::FEM::RElementType type) const override;

    std::pair<SG::DataStructure::FEM::RElementType, std::size_t>
    FindRElement (SG::DataStructure::Common::Id eleId, const std::vector<SG::DataStructure::FEM::RElementType>& etypes = {}) const override;

    std::vector<SG::DataStructure::Common::Id> GetAllRElementId () const override;

    SG::DataStructure::Common::Status CopyData (DBServiceFactory* const dest, std::vector<SG::DataStructure::Common::Id> id) const;

  public:
    // summary创建时 用来将各表的需要注册的函数注册进去
    using SummaryCreateService = std::function<void (DBServiceFactory* const)>;

    static bool RegisterService (SummaryCreateService&& service);

    static void CreateSummary (DBServiceFactory* const dbServiceFactory);
};

SG_DBMANAGER_NAMESPACE_CLOSE
